package com.example.springboot.mapper;

import com.example.springboot.controller.request.BookPageRequest;
import com.example.springboot.entity.Book;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BookMapper {
//    @Select("select * from book")
    List<Book> list();

    List<Book> listByCondition(BookPageRequest bookPageRequest);

    void save(Book book);

    // 根据 title 查询书籍
    Book findByTitle(String title);

    // 更新书籍数量
    void updateTotalCopies(Book book);

    Book findById(Long bookId);

    void updateBook(Book book);

    @Select("SELECT COUNT(*) FROM book")
    int countTotalBooks();

    @Update("UPDATE book SET totalCopies = totalCopies + 1 WHERE title = #{title}")
    void incrementTotalCopiesByTitle(String title);

}
